package com.burgeon.backend.SHOPBACKEND.rest;

import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.SHOPBACKEND.entity.FOrder;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

/*云仓订单发货单*/
public class QuerryYcRetalloutByIsTs extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public QuerryYcRetalloutByIsTs(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }


    /**
     * 发送并接收字符创
     * @return
     */

    public ArrayList<FOrder> getData() throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";
        String str = RESULT(Data(), url);
        //System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        if (!"0".equals(code)) {
            throw new Exception(str);
        }
        String count = new JSONArray(str).getJSONObject(0).getString("count");
        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");

        ArrayList<FOrder> orderArrayList = new ArrayList<FOrder>();

        for (int i = 0; i < jsonArray.length(); i++) {
            JSONArray array = jsonArray.getJSONArray(i);

            FOrder forder = new FOrder();

            forder.setId(jsonArray.getJSONArray(i).getString(0));
//            forder.setcExpresscompanyId(jsonArray.getJSONArray(i).getString(1));
//            forder.setExpresscompanyNo(jsonArray.getJSONArray(i).getString(2));
//            forder.setStaus(jsonArray.getJSONArray(i).getString(3));
            forder.setIsUp(jsonArray.getJSONArray(i).getString(1));
            forder.setcStoreId(jsonArray.getJSONArray(i).getString(2));
            forder.setDocno(jsonArray.getJSONArray(i).getString(3));
            forder.setCreationDate(jsonArray.getJSONArray(i).getString(4));
            forder.setHrEmployee(jsonArray.getJSONArray(i).getString(5));
            forder.setHrEmployeePhone(jsonArray.getJSONArray(i).getString(6));
            forder.setVipName(jsonArray.getJSONArray(i).getString(7));
            forder.setVipPhone(jsonArray.getJSONArray(i).getString(8));
            forder.setYcDocno(jsonArray.getJSONArray(i).getString(9));

            orderArrayList.add(forder);
        }
        return orderArrayList;
    }

    private MultiValueMap Data() {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段

        columns.add("ID");
//        columns.add("'C_EXPRESSCOMPANY_ID;NAME'");//快递公司 EB_LOGIS_ID  FASTNO
//        columns.add("EXPRESSCOMPANY_NO");//快递单号
//        columns.add("STATUS");//快递单号
        columns.add("IS_UP");
        columns.add("'C_STORE_ID;NAME'");//	发货店仓
        columns.add("DOCNO");
        columns.add("CREATIONDATE");//创建时间
        columns.add("'C_VIP_ID;HR_EMPLOYEE_ID1;NAME'");
        columns.add("'C_VIP_ID;HR_EMPLOYEE_ID1;PHONE'");
        columns.add("'C_VIP_ID;VIPNAME'");
        columns.add("'C_VIP_ID;MOBIL'");
        columns.add("'YC_RETAIL_ID;DOCNO'");

        params.put("columns", columns);
        params.put("table", "YC_RETAILOUT");//表名

        params.put("count","true");

        HashMap paramss = new HashMap();//DOCNO  (AK)	单据编号
        String status = "'=1'";
        paramss.put("column", "STATUS");
        paramss.put("condition", status);
//        HashMap expr1 = new HashMap();
//
//        HashMap expr1v1 = new HashMap();
//        String ac = "'=1'";
//        expr1v1.put("column", "IS_UP");//STATUS；IS_UP
//        expr1v1.put("condition", ac);
//
//        HashMap expr1v2 = new HashMap();
//        String it = "'=Y'";
//        expr1v2.put("column", "IS_TS");
//        expr1v2.put("condition", it);
//        expr1.put("combine", "and");//关系
//        expr1.put("expr1",expr1v1);
//        expr1.put("expr2",expr1v2);
//
//        HashMap expr2 = new HashMap();
//        String status = "'=1'";
//        expr2.put("column", "STATUS");
//        expr2.put("condition", status);



//        HashMap expr2 = new HashMap();
//        String e = "null";
//        expr2.put("column", "C_EXPRESSCOMPANY_ID");//	快递公司
//        expr2.put("condition", e);

//        paramss.put("combine", "and");//关系
//        paramss.put("expr1",expr1);
//        paramss.put("expr2",expr2);

        params.put("params", paramss);
        //System.err.println(params);

        return DATA("Query", params,account,password);
    }

    public static void main(String[] args) {
        QuerryYcRetalloutByIsTs querryYCRetailout = new QuerryYcRetalloutByIsTs("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {
            System.err.println(querryYCRetailout.getData());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
